#include "CurrentThread.h"

namespace CurrentThread {
    __thread pid_t t_cachedTid = 0;  // 定义线程局部变量

    void cacheTid() {
        if (t_cachedTid == 0) {
            t_cachedTid = static_cast<pid_t>(syscall(SYS_gettid));
        }
    }

    pid_t tid() {
        if (__builtin_expect(t_cachedTid == 0, 0)) {
            cacheTid();
        }
        return t_cachedTid;
    }
}